@import '../../var.less';

.vcu-button {
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  height: @button-default-height;
  margin: 0;
  padding: 0;
  font-size: @button-default-font-size;
  line-height: @button-default-line-height;
  text-align: center;
  border-radius: @button-border-radius;
  cursor: pointer;
  transition: opacity @animation-duration-fast;
  -webkit-appearance: none;

  &::before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: @black;
    border: inherit;
    border-color: @black;
    border-radius: inherit; /* inherit parent's border radius */
    transform: translate(-50%, -50%);
    opacity: 0;
    content: ' ';
  }

  &:active::before {
    opacity: 0.1;
  }

  &--loading,
  &--disabled {
    &::before {
      display: none;
    }
  }

  &--default {
    color: @button-default-color;
    background: @button-default-background-color;
    border: @button-border-width solid
      @button-default-border-color;
  }

  &--primary {
    color: @button-primary-color;
    background: @button-primary-background-color;
    border: @button-border-width solid
      @button-primary-border-color;
  }

  &--success {
    color: @button-success-color;
    background: @button-success-background-color;
    border: @button-border-width solid
      @button-success-border-color;
  }

  &--danger {
    color: @button-danger-color;
    background: @button-danger-background-color;
    border: @button-border-width solid
      @button-danger-border-color;
  }

  &--warning {
    color: @button-warning-color;
    background: @button-warning-background-color;
    border: @button-border-width solid
      @button-warning-border-color;
  }

  &--link {
    color: @button-default-color;
    background: none;
    border: 0;
  }

  &--plain {
    background: @button-plain-background-color;

    &.vcu-button--primary {
      color: @button-primary-background-color;
    }

    &.vcu-button--success {
      color: @button-success-background-color;
    }

    &.vcu-button--danger {
      color: @button-danger-background-color;
    }

    &.vcu-button--warning {
      color: @button-warning-background-color;
    }
  }

  &--large {
    width: 100%;
    height: @button-large-height;
  }

  &--normal {
    padding: @button-normal-padding;
    font-size: @button-normal-font-size;
  }

  &--small {
    height: @button-small-height;
    padding: @button-small-padding;
    font-size: @button-small-font-size;
  }

  &__loading {
    color: inherit;
    font-size: inherit;

    .vcu-loading__spinner {
      color: currentColor;
      width: @button-loading-icon-size;
      height: @button-loading-icon-size;
    }
  }

  &--mini {
    height: @button-mini-height;
    padding: @button-mini-padding;
    font-size: @button-mini-font-size;

    & + .vcu-button--mini {
      margin-left: @padding-base;
    }
  }

  &--block {
    display: block;
    width: 100%;
  }

  &--disabled {
    cursor: not-allowed;
    opacity: @button-disabled-opacity;
  }

  &--loading {
    cursor: default;
  }

  &--round {
    border-radius: @button-round-border-radius;
  }

  &--square {
    border-radius: 0;
  }

  // align-items are ignored when flex container is a button in legacy safari
  &__content {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;

    // fix icon vertical align
    &::before {
      content: ' ';
    }
  }

  &__icon {
    font-size: @button-icon-size;
    line-height: inherit;
  }

  &__icon + &__text,
  &__loading + &__text,
  &__text + &__icon,
  &__text + &__loading {
    margin-left: @padding-base;
  }

  &--hairline {
    border-width: 0;

    &::after {
      border-color: inherit;
      border-radius: calc(@button-border-radius * 2);
    }

    &.vcu-button--round::after {
      border-radius: @button-round-border-radius;
    }

    &.vcu-button--square::after {
      border-radius: 0;
    }
  }
}
